"""add ai_config

Revision ID: 1e3f7e4d7933
Revises: 41a570db9ebf
Create Date: 2025-04-09 14:27:17.409874

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = '1e3f7e4d7933'
down_revision: Union[str, None] = '41a570db9ebf'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('ai_config',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('config_key', sa.String(length=255), server_default=sa.text("''"), nullable=False, comment='配置key'),
    sa.Column('config_value', sa.String(length=255), server_default=sa.text("''"), nullable=False, comment='配置值'),
    sa.Column('config_name', sa.String(length=255), server_default=sa.text("''"), nullable=False, comment='配置名称'),
    sa.Column('description', sa.String(length=255), nullable=False, comment='描述'),
    sa.Column('remark', sa.String(length=255), nullable=False, comment='备注'),
    sa.Column('is_system', sa.String(length=16), server_default=sa.text("'NO'"), nullable=False, comment='系统默认'),
    sa.Column('created_at', sa.TIMESTAMP(), nullable=False),
    sa.Column('updated_at', sa.TIMESTAMP(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_ai_config_id'), 'ai_config', ['id'], unique=False)
    op.alter_column('ai_agents', 'system_prompt',
               existing_type=mysql.LONGTEXT(collation='utf8mb4_general_ci'),
               type_=sa.TEXT(length=16777216),
               existing_nullable=True)
    op.alter_column('ai_api', 'is_system',
               existing_type=mysql.VARCHAR(collation='utf8mb4_general_ci', length=16),
               comment='系统默认',
               existing_comment='状态',
               existing_nullable=False,
               existing_server_default=sa.text("'NO'"))
    op.alter_column('funcall_log', 'log_text',
               existing_type=mysql.LONGTEXT(collation='utf8mb4_general_ci'),
               type_=sa.TEXT(length=16777216),
               existing_comment='日志信息',
               existing_nullable=True)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('funcall_log', 'log_text',
               existing_type=sa.TEXT(length=16777216),
               type_=mysql.LONGTEXT(collation='utf8mb4_general_ci'),
               existing_comment='日志信息',
               existing_nullable=True)
    op.alter_column('ai_api', 'is_system',
               existing_type=mysql.VARCHAR(collation='utf8mb4_general_ci', length=16),
               comment='状态',
               existing_comment='系统默认',
               existing_nullable=False,
               existing_server_default=sa.text("'NO'"))
    op.alter_column('ai_agents', 'system_prompt',
               existing_type=sa.TEXT(length=16777216),
               type_=mysql.LONGTEXT(collation='utf8mb4_general_ci'),
               existing_nullable=True)
    op.drop_index(op.f('ix_ai_config_id'), table_name='ai_config')
    op.drop_table('ai_config')
    # ### end Alembic commands ###
